#include <event2/event.h>
#include <signal.h>

static timeval t1 = {1, 0};
void timer1_cb(int sock, short which, void *arg)
{
    printf("tick\r\n");
    event *tim = (event*)arg;
    if(!evtimer_pending(tim, &t1)){
        evtimer_del(tim);
        evtimer_add(tim, &t1);
    }
}
void timer2_cb(int sock, short which, void *arg)
{
    printf("tick2\r\n");  
}
void timer3_cb(int sock, short which, void *arg)
{
    printf("tick3\r\n"); 
}

int main() {
    /* ignore pipe signal */
    if(signal(SIGPIPE, SIG_IGN) == SIG_ERR)
    {
        return 1;
    }
    event_base *base = event_base_new();
    
    event *timer1 = evtimer_new(base, timer1_cb, event_self_cbarg());
    evtimer_add(timer1, &t1);

    static timeval t2;
    t2.tv_sec = 2;
    t2.tv_usec = 500000;
    event *timer2 = event_new(base, -1, EV_PERSIST, timer2_cb, 0);
    event_add(timer2, &t2);

    event *timer3 = event_new(base, -1, EV_PERSIST, timer3_cb, 0);
    static timeval tv_in = {3, 0};
    const timeval *t3;
    t3 = event_base_init_common_timeout(base, &tv_in);
    event_add(timer3, t3);

    event_base_dispatch(base);
    event_base_free(base);

    return 1;

}